$('.right-titleicon').on("click", function(e) {
	projectVM.showMenulist()
})
var timeOut;
projectVM = new Vue({
	el: "#content",
	components: {
		personselect
	},
	data: {
		isSingle: false,
		onStatus: false,
		showPop: false,
		showMenu: false,
		menuList: [{
			name: '交班',
			path: 'handOver.html'
		}, {
			name: '接班',
			path: 'handOver.html'
		}, {
			name: '列表',
			path: 'index.html'
		}, ],
		filterText: 'all', //筛选条件
		currentUser: {},
		list: [],
		searchData: {
			areaCompanyCode: '',
			stationCode: '',
			role: '',
			keyWord: '',
			ifConfirm: '',
		},
		pageSize: '10',
		current: '1',
		total: '0',
	},

	created() {
		// 获取local数据
		console.log(JSON.parse(localStorage.getItem('neiosUser')))
		this.currentUser = JSON.parse(localStorage.getItem('neiosUser'))
		this.searchData.areaCompanyCode = this.currentUser.companyNewCode
		this.searchData.stationCode = this.currentUser.stationNewCode
		this.searchData.role = this.currentUser.roles
		//网络安全列表
		this.getList()
		this.$nextTick(()=>{
			var oDiv =document.getElementById("myTop")
			        //div在页面的占位高，div到body的距离
			        var otop = oDiv.offsetTop;
			        //页面滚动
			        window.onscroll = function() {
			           //获取页面的滚动距离
			            var oheight = document.documentElement.scrollTop || document.body.scrollTop;
			            //滚动到一定位置 div固定到顶部 js实现吸顶
			            if (otop < oheight) {
			                oDiv.style.position = "fixed";
			                oDiv.style.top = otop+'px';
			            } else {
			                oDiv.style.position = "relative";
							oDiv.style.top = 0;
			            }
			        }
		})
		
	},
	methods: {
		del(data) {
			
			var btnArray = ['取消', '确定'];
			mui.confirm('是否确认删除？', '提示', btnArray, (e) => {
				if (e.index == 1) {
					let param = {
						"changeShiftsId": data,
						"currentUser": this.currentUser
					}
					//获取列表
					mui.neiosRequst.httpRequst('/app/currentEntry/changeShift/deleteChangeShiftById', param,
						(data) => {
							if (data.code == '0') {
								mui.toast("删除成功：" + data.msg);
								this.getList()
							} else {
								mui.toast("删除失败：" + data.msg);
							}
						},
						(data) => {
							mui.toast("删除失败：" + data.msg);
						}
					);
				} else {

				}
			})
		},
		clearInput(){
			this.searchData.keyWord = ''
			this.current = 1
			this.list = []
			this.getList()
		},
		getList() {
			let param = {
				"searchType": "keyWord",
				"queryChangeShift": this.searchData,
				"pageSize": this.pageSize,
				"current": this.current
			}
			console.log(JSON.stringify(param),'===')
			
			//获取列表
			mui.neiosRequst.httpRequst('/app/currentEntry/changeShift/getChangeShiftByPage', param,
				(data) => {
					if (data.code == '0') {
						this.list = data.data ? data.data.records : []
						this.diffCurrentId = data.data ? data.data.diffCurrentId : ''
						this.total = data.data.total
					} else {
						mui.toast("获取数据失败：" + data.msg);
					}
				},
				(data) => {
					mui.toast("获取数据失败：" + data.msg);
				}
			);

		},
		searchKey(e) {
			clearTimeout(timeOut)
			console.log(e.target.value)
			timeOut = setTimeout(() => {
				this.getList()
			}, 500)

		},
		clickStop() {

		},
		navTo(e,data) {
			localStorage.setItem("workId", data);
			mui.openWindow({
				url: e,
				id: e,
				extras: {},
				waiting: {
					autoShow: false
				}
			});
		},
		//点击菜单
		menuClick(e) {
			this.showMenu = false
			if(e.name == '交班'){
				this.navTo(e.path)
			}else if(e.name == '接班'){
				let param = {"workType": "0201","userId":this.currentUser.userId}
				//获取列表
				mui.neiosRequst.httpRequst('/app/currentEntry/changeShift/loadToDoByWorkType', param,
					(data) => {
						if (data.code == '0') {
							if(data.data.length>0){
								this.navTo(e.path,data.data[0].workId)
							}else{
								mui.toast("暂无数据");
							}
							
						} else {
							mui.toast("获取数据失败：" + data.msg);
						}
					},
					(data) => {
						mui.toast("获取数据失败：" + data.msg);
					}
				);
			}else{
				this.navTo(e.path)
			}

		},
		//左上角菜单显示隐藏
		showMenulist() {
			this.showMenu ? this.showMenu = false : this.showMenu = true
		},
		//切换筛选条件
		changeFliter(e) {
			this.filterText = e
			if (e == 'return') {
				this.searchData.ifConfirm = 1
			} else if (e == 'unreturn') {
				this.searchData.ifConfirm = 0
			} else {
				this.searchData.ifConfirm = ''
			}
			this.getList()
		},
		showPop() {
			this.show_popup = true
		},
		hidePopup() {
			this.show_popup = false
		},

	}

})

 mui('.mui-input-clear')[0].addEventListener('focus',function(){
				mui('.mui-icon-clear')[0].addEventListener('tap',function(){
					projectVM.clearInput()
				})
			})	
mui.plusReady(function () {
	 console.log(plus.webview.currentWebview().id) 
     window.addEventListener('param', function(event) { // 通过人员权限接口来判断是否显示现场运维入口
		projectVM.current = 1
	   projectVM.getList()
      });
})


mui.init({
	pullRefresh: {
		container: "#scroll", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
		down: { //下拉刷新
			style: 'circle',
			height: 50, //可选,默认50.触发下拉刷新拖动距离,
			auto: false, //可选,默认false.首次加载自动下拉刷新一次
			contentdown: "下拉可以刷新", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
			contentover: "释放立即刷新", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
			contentrefresh: "正在刷新...", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容
			callback:  function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				projectVM.current = 1
				mui('#scroll').pullRefresh().refresh(true);
				//网络安全列表
				let param = {
					"searchType": "keyWord",
					"queryChangeShift": projectVM.searchData,
					"pageSize": projectVM.pageSize,
					"current": projectVM.current
				}
				//获取列表
				mui.neiosRequst.httpRequst('/app/currentEntry/changeShift/getChangeShiftByPage', param,
					(data) => {
						if (data.code == '0') {
							projectVM.list = data.data ? data.data.records : []
							projectVM.diffCurrentId = data.data ? data.data.diffCurrentId : ''
							if (projectVM.list.length == 0) {
								mui('#scroll').pullRefresh().endPulldownToRefresh(true);
							} else {
								mui('#scroll').pullRefresh().endPulldownToRefresh();
								// mui('#scroll').pullRefresh().refresh(true);

							}
						} else {
							mui.toast("获取数据失败：" + data.msg);
						}
					},
					(data) => {
						mui.toast("获取数据失败：" + data.msg);
					}
				);

				////没有更多内容了，endPulldown 传入true， 不再执行下拉刷新

			}
		},
		up: { //上拉加载
			height: 50, //可选.默认50.触发上拉加载拖动距离
			auto: false, //可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
			contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
			callback:  function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				let limit = Math.ceil(Number(projectVM.total) / Number(projectVM.pageSize))
				console.log(limit, projectVM.current)
				if (limit > projectVM.current) {
					//网络安全列表
					projectVM.current = Number(projectVM.current) + 1
					let param = {
						"searchType": "keyWord",
						"queryChangeShift": projectVM.searchData,
						"pageSize": projectVM.pageSize,
						"current": projectVM.current
					}
					//获取列表
					mui.neiosRequst.httpRequst('/app/currentEntry/changeShift/getChangeShiftByPage', param,
						(data) => {
							if (data.code == '0') {  
								if (data.data) {
									projectVM.list = projectVM.list.concat(data.data.records)
								}
								if (data.data.records.length == 0) {
									mui('#scroll').pullRefresh().endPullupToRefresh(true);
								} else {
									mui('#scroll').pullRefresh().endPullupToRefresh();
								}
							} else {
								mui.toast("获取数据失败：" + data.msg);
							}
						},
						(data) => {
							mui.toast("获取数据失败：" + data.msg);
						}
					);
				} else {
					mui('#scroll').pullRefresh().endPullupToRefresh(true);

				}


			}
		}
	}
});
